#include <iostream>
#include <unordered_map>
#include <cmath>

std::string word_to_digit(std::string word) {
    std::unordered_map<std::string, std::string> words = {
        {"zero", "0"},
        {"one", "1"},
        {"two", "2"},
        {"three", "3"},
        {"four", "4"},
        {"five", "5"},
        {"six", "6"},
        {"seven", "7"},
        {"eight", "8"},
        {"nine", "9"}
    };
    return words.find(word) != words.end() ? words[word] : "";
}

bool is_prime(int n) {
    if (n <= 1)
        return false;
    for (int i = 2; i <= std::sqrt(n); i++) {
        if (n % i == 0)
            return false;
    }
    return true;
}

int main() {
    std::string input;
    std::getline(std::cin, input);
    std::istringstream iss(input);
    std::vector<std::string> words;
    std::string word;
    while (iss >> word) {
        words.push_back(word);
    }
    if (words.size() != 3) {
        std::cout << "Wrong input" << std::endl;
        return 0;
    }
    std::string g_str = "";
    for (const auto& w : words) {
        g_str += word_to_digit(w);
    }
    if (!std::all_of(g_str.begin(), g_str.end(), ::isdigit) || g_str.length() != 3) {
        std::cout << "Wrong input" << std::endl;
        return 0;
    }
    int g = std::stoi(g_str);
    int a = -1, c = -1;
    int i = 1;
    while (true) {
        if (g - i >= 0 && is_prime(g - i)) {
            a = g - i;
            break;
        }
        if (is_prime(g + i)) {
            c = g + i;
            break;
        }
        i++;
    }
    if (a != -1)
        std::cout << a << std::endl;
    if (c != -1)
        std::cout << c << std::endl;
    return 0;
}